package com.alipay.app.groupmeal.standard.ui.b.util;

import android.content.Context;

import androidx.lifecycle.Lifecycle;


import com.trello.rxlifecycle4.LifecycleProvider;


import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.ObservableTransformer;
import io.reactivex.rxjava3.schedulers.Schedulers;


public class RxHelper {


    public static <T> ObservableTransformer<T, T> rxSchedulerHelper() {
        return observable -> observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }

    public static <T> ObservableTransformer<T, T> rxSchedulerHelper2() {
        return observable -> observable.subscribeOn(Schedulers.io())
                .observeOn(Schedulers.io());
    }
//
//    public static <T> ObservableTransformer<T, T> observableIO2Main(final RxFragment fragment) {
//        return upstream -> upstream.subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread()).compose(fragment.<T>bindToLifecycle());
//    }
//
//    public static <T> FlowableTransformer<T, T> flowableIO2Main() {
//        return new FlowableTransformer<T, T>() {
//            @Override
//            public Publisher<T> apply(Flowable<T> upstream) {
//                return upstream
//                        .subscribeOn(Schedulers.io())
//                        .observeOn(AndroidSchedulers.mainThread());
//            }
//        };
//    }
//
//    private static <T> ObservableSource<T> composeContext(Context context, Observable<T> observable) {
//        if (context instanceof RxActivity) {
//            return observable.compose(((RxActivity) context).bindUntilEvent(ActivityEvent.DESTROY));
//        } else if (context instanceof RxFragmentActivity) {
//            return observable.compose(((RxFragmentActivity) context).bindUntilEvent(ActivityEvent.DESTROY));
//        } else if (context instanceof RxAppCompatActivity) {
//            return observable.compose(((RxAppCompatActivity) context).bindUntilEvent(ActivityEvent.DESTROY));
//        } else {
//            return observable;
//        }
//    }

}
